package com.example.yls.demoa;

import android.graphics.Color;
import android.nfc.Tag;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;

public class MainActivity extends AppCompatActivity {
    LinearLayout mBottomSheet;
    private BottomSheetBehavior<LinearLayout> mBottomSheetBehavior;
    private Button open_close;
    private BottomNavigationBar mIdBnb;
    private Boolean isOpen=false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mBottomSheet=findViewById(R.id.bottom_sheet);
        mBottomSheetBehavior=BottomSheetBehavior.from(mBottomSheet);
        mIdBnb=findViewById(R.id.id_bnb);

        mIdBnb.addItem(new BottomNavigationItem(R.drawable.icon, "about")
                .setActiveColor(Color.RED));
        mIdBnb.addItem(
                new BottomNavigationItem(R.drawable.icon, "before")
                        .setActiveColor(Color.BLUE));
        mIdBnb.addItem(
                new BottomNavigationItem(R.drawable.icon, "card")
                        .setActiveColor(Color.GREEN));
        mIdBnb.addItem(
                new BottomNavigationItem(R.drawable.icon, "dall")
                        .setActiveColor(Color.YELLOW));
        mIdBnb.addItem(
                new BottomNavigationItem(R.drawable.icon, "element")
                        .setActiveColor(Color.CYAN));
        mIdBnb.initialise();




        mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View view, int i) {
                Log.e("MainActivity","newstate"+i);
            }

            @Override
            public void onSlide(@NonNull View view, float v) {
                Log.e("MainActivity","onslide"+v);
            }
        });
        /*设置按钮打开或关闭bottomSheet */
        open_close=findViewById(R.id.open_close);
        open_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
           new MyBSDFragment().show(getSupportFragmentManager(),"MainActivity");


             /*   if (isOpen==true){
               mBottomSheetBehavior.setState(mBottomSheetBehavior.STATE_COLLAPSED);
               isOpen=!isOpen;
                }
                else{
                    mBottomSheetBehavior.setState(mBottomSheetBehavior.STATE_EXPANDED);
                    isOpen=!isOpen;
                }*/
            }
        });
        /*设置点击事件*/
        findViewById(R.id.tv_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tv_1被单击", Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.tv_2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tv_2被单击", Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.tv_3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tv_3被单击", Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.tv_4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tv_4被单击", Toast.LENGTH_SHORT).show();
            }
        });




    }
}
